package com.hxt.framework.utils;

import java.util.List;

import com.hxt.framework.msg.RequestMsg;

import net.sf.oval.ConstraintViolation;
import net.sf.oval.Validator;

public class ValidateUtils {
	public static void ovalValidate(Object obj,String... profile){
		if(obj==null){
			throw new JpException("400", "参数为空");
		}
		Validator v=new Validator();
		List<ConstraintViolation> errList=null;
		if(profile!=null&&profile.length>0){
			errList= v.validate(obj,profile);
		}else{
			errList= v.validate(obj);
		}
		if(errList==null || errList.isEmpty()){
			return;
		}
		ConstraintViolation error = errList.get(0);
		throw new JpException("400",error.getMessage());
	}
	
	public static void validateUserOrgan(RequestMsg<?>req){
		if(req.getUserId()==null){
			throw new JpException("400", "用户id为空");
		}
		if(req.getOrganId()==null){
			throw new JpException("400", "机构id为空");
		}
	}
}
